package com.yjy.mybase.mvp;

import java.lang.ref.WeakReference;


/**
 * 交互层
 * Created by Serenade on 2017/8/17.
 */
public abstract class MVPBasePresenter<V extends BaseContract.View, M extends MVPBaseModel> {
    protected WeakReference<V> mView;
    protected M mModel;

    public MVPBasePresenter() {
        mModel = createModel();
    }

    public void attach(V mView) {
        this.mView = new WeakReference<V>(mView);
    }

    public void detach() {
        if (mView != null) {
            mView.clear();
        }
    }

    public boolean isAttach() {
        return mView != null;
    }

    public V getView() {
        return mView.get();
    }

    public M getModel() {
        return mModel;
    }

    public abstract M createModel();
}